/**
 * @author: gao
 * @create-date: 2025/3/10 10:33
 */

public class Solution {
    public int subarray(int[] nums,int k){
        int count = 0,sum = 0;;
        for(int left = 0,right = 0;right < nums.length;right++){
            sum += nums[right];
            while(sum == k){
                count++;
                sum -= nums[left];
                left++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int[] array = new int[]{1,1,1};
        int k = 2;
        Solution solution = new Solution();
        System.out.println(solution.subarray(array, 2));
        System.out.println();
    }
}
